var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/LoginForm/index.tsx
var LoginForm_exports = {};
__export(LoginForm_exports, {
  default: () => LoginForm
});
module.exports = __toCommonJS(LoginForm_exports);
var import_EyeInvisibleOutlined = __toESM(require("@ant-design/icons/EyeInvisibleOutlined"));
var import_EyeOutlined = __toESM(require("@ant-design/icons/EyeOutlined"));
var import_ReloadOutlined = __toESM(require("@ant-design/icons/ReloadOutlined"));
var import_hooks = require("@szzj/hooks");
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_style = require("antd/es/button/style/index.js");
var import_style2 = require("antd/es/form/style/index.js");
var import_style3 = require("antd/es/input/style/index.js");
var import_index = require("./index.less");
var FormItem = import_antd.Form.Item;
function LoginForm({
  size = "large",
  passwordRules = [],
  getCaptureUrl,
  onLogin
}) {
  const { fetch: fetchCaptureUrl, data: captureUrl } = (0, import_hooks.useFetch)(getCaptureUrl ?? (() => Promise.resolve(void 0)));
  const [form] = import_antd.Form.useForm();
  const handleSubmit = () => {
    form.validateFields().then((fields) => {
      onLogin(fields).then((res) => {
        if (!(res == null ? void 0 : res.success)) {
          fetchCaptureUrl();
        }
      });
    }).catch((err) => console.warn(err));
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("szzj-login-form", size) }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form,
    {
      form,
      validateTrigger: "onBlur",
      scrollToFirstError: true,
      onKeyUp: (event) => {
        if (event.key === "enter")
          handleSubmit();
      },
      onFinish: handleSubmit
    },
    /* @__PURE__ */ import_react.default.createElement(
      FormItem,
      {
        name: "account",
        rules: [
          {
            required: true,
            whitespace: true,
            message: "请输入用户名"
          }
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { placeholder: "请输入用户名", size, maxLength: 50 })
    ),
    /* @__PURE__ */ import_react.default.createElement(
      FormItem,
      {
        name: "password",
        rules: [
          {
            required: true,
            whitespace: true,
            message: "请输入密码"
          },
          ...passwordRules
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Input.Password,
        {
          placeholder: "请输入密码",
          size,
          maxLength: 30,
          iconRender: (visible) => visible ? /* @__PURE__ */ import_react.default.createElement(import_EyeOutlined.default, null) : /* @__PURE__ */ import_react.default.createElement(import_EyeInvisibleOutlined.default, null)
        }
      )
    ),
    getCaptureUrl && /* @__PURE__ */ import_react.default.createElement(import_react.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      FormItem,
      {
        name: "imageCode",
        rules: [
          {
            required: true,
            whitespace: true,
            message: "请输入验证码"
          }
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { size, placeholder: "请输入验证码", maxLength: 4 })
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-login-form-capture-wrapper" }, /* @__PURE__ */ import_react.default.createElement(
      "img",
      {
        alt: "图片验证码",
        src: captureUrl,
        className: "szzj-login-form-capture"
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      "a",
      {
        className: "szzj-login-form-capture-tips",
        onClick: fetchCaptureUrl
      },
      /* @__PURE__ */ import_react.default.createElement(import_ReloadOutlined.default, { className: "szzj-login-form-capture-icon" }),
      "换一张"
    ))),
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        htmlType: "submit",
        type: "primary",
        size,
        className: "szzj-login-form-button"
      },
      "登录"
    )
  ));
}
